package com.czxy.service;

import com.czxy.dao.UserMapper;
import com.czxy.domain.User;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional
public class UserServiceImpl implements UserService{

    @Resource
    private UserMapper userMapper;


    @Override
    public PageInfo findByInfo(Integer pageNum, Integer pageSize, User user) {

        Example example = new Example(User.class);
        Example.Criteria ct = example.createCriteria();


        if (user.getLoginName() !=null && !"".equals(user.getLoginName())){

            ct.andLike("loginName","%"+user.getLoginName()+"%");
        }

        // 条件二:学历
        if(user.getEducation() !=null && !"".equals(user.getEducation())){
            ct.andEqualTo("education", user.getEducation());
        }
        // 条件三:性别
        if(user.getSex() !=null && !"".equals(user.getSex())){
            ct.andEqualTo("sex", user.getSex());
        }


        PageHelper.startPage(pageNum,pageSize);

        List<User> list = userMapper.selectByExample(example);

        PageInfo<User> pageInfo = new PageInfo<>(list);


        return pageInfo;
    }







}
